/**
 * 
 */
package com.et114.modules.products.commons;

import java.util.Date;
import java.util.List;

import com.et114.core.services.impl.BaseServicesImpl;
import com.et114.modules.products.card.services.CardServiceImpl;
import com.et114.modules.products.card.vo.Card;
import com.et114.modules.products.cellphone.services.CellPhoneServiceImpl;
import com.et114.modules.products.cellphone.vo.CellPhone;
import com.et114.modules.products.digitalTv.services.DigitalTvServiceImpl;
import com.et114.modules.products.digitalTv.vo.DigitalTv;
import com.et114.modules.products.netbook.services.NetBookServiceImpl;
import com.et114.modules.products.netbook.vo.NetBook;
import com.et114.modules.products.securitydoor.services.SecuritySystemServiceImpl;
import com.et114.modules.products.securitydoor.vo.SecurityDoor;

/*
 * @author guanhw
 */
public class ProOffTimeTask extends BaseServicesImpl {
	private CellPhoneServiceImpl		cellPhoneServiceImpl;
	private NetBookServiceImpl			netBookServiceImpl;
	private CardServiceImpl				cardServiceImpl;
	private DigitalTvServiceImpl		digitalTvServiceImpl;
	private SecuritySystemServiceImpl	securitySystemServiceImpl;
	
	public void setCellPhoneServiceImpl (
			CellPhoneServiceImpl cellPhoneServiceImpl ) {
		this.cellPhoneServiceImpl = cellPhoneServiceImpl;
	}
	
	public void setNetBookServiceImpl ( NetBookServiceImpl netBookServiceImpl ) {
		this.netBookServiceImpl = netBookServiceImpl;
	}
	
	public void setDigitalTvServiceImpl (
			DigitalTvServiceImpl digitalTvServiceImpl ) {
		this.digitalTvServiceImpl = digitalTvServiceImpl;
	}
	
	public void setCardServiceImpl ( CardServiceImpl cardServiceImpl ) {
		this.cardServiceImpl = cardServiceImpl;
	}
	
	public void setSecuritySystemServiceImpl (
			SecuritySystemServiceImpl securitySystemServiceImpl ) {
		this.securitySystemServiceImpl = securitySystemServiceImpl;
	}
	
	public void doTask ( ) {
		Date now = new Date ( );
		try {
			CellPhone cellPhone = new CellPhone ( );
			cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
			List < CellPhone > cellPhones = cellPhoneServiceImpl
					.getCellPhonesHasOffTime ( cellPhone );
			cellPhone = null;
			for ( CellPhone vo : cellPhones ) {
				if ( ( now.getTime ( ) - vo.getOffTime ( ).getTime ( ) ) >= 0 ) {
					cellPhone = new CellPhone ( );
					cellPhone.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT );
					cellPhone.setProId ( vo.getProId ( ) );
					cellPhoneServiceImpl
							.updateCellPhoneProOnOffStatus ( cellPhone );
				}
			}
			
			now = new Date ( );
			NetBook netBook = new NetBook ( );
			netBook.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
			List < NetBook > netBooks = netBookServiceImpl
					.getNetBooksHasOffTime ( netBook );
			netBook = null;
			for ( NetBook vo : netBooks ) {
				if ( ( now.getTime ( ) - vo.getOffTime ( ).getTime ( ) ) >= 0 ) {
					netBook = new NetBook ( );
					netBook.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT );
					netBook.setProId ( vo.getProId ( ) );
					netBookServiceImpl.updateNetBookProOnOffStatus ( netBook );
				}
			}
			
			now = new Date ( );
			Card card = new Card ( );
			card.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
			List < Card > cards = cardServiceImpl.getCardsHasOffTime ( card );
			card = null;
			for ( Card vo : cards ) {
				if ( ( now.getTime ( ) - vo.getOffTime ( ).getTime ( ) ) >= 0 ) {
					card = new Card ( );
					card.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT );
					card.setProId ( vo.getProId ( ) );
					cardServiceImpl.updateCardProOnOffStatus ( card );
				}
			}
			
			now = new Date ( );
			DigitalTv digitalTv = new DigitalTv ( );
			digitalTv.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
			List < DigitalTv > dts = digitalTvServiceImpl
					.getDigitalTvsHasOffTime ( digitalTv );
			digitalTv = null;
			for ( DigitalTv vo : dts ) {
				if ( ( now.getTime ( ) - vo.getOffTime ( ).getTime ( ) ) >= 0 ) {
					digitalTv = new DigitalTv ( );
					digitalTv.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT );
					digitalTv.setProId ( vo.getProId ( ) );
					digitalTvServiceImpl
							.updateDigitalTvProOnOffStatus ( digitalTv );
				}
			}
			
			now = new Date ( );
			SecurityDoor securitySystem = new SecurityDoor ( );
			securitySystem.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUBED );
			List < SecurityDoor > securitySystems = securitySystemServiceImpl
					.getSecuritySystemsHasOffTime ( securitySystem );
			securitySystem = new SecurityDoor ( );
			for ( SecurityDoor vo : securitySystems ) {
				if ( ( now.getTime ( ) - vo.getOffTime ( ).getTime ( ) ) >= 0 ) {
					securitySystem = new SecurityDoor ( );
					securitySystem
							.setProOnOffStatus ( Const.PRO_PUB_STATUS_PUB_OUT );
					securitySystem.setProId ( vo.getProId ( ) );
					securitySystemServiceImpl
							.updateSecuritySystemProOnOffStatus ( securitySystem );
				}
			}
		} catch ( Exception ex ) {
			logger.error ( ex.getMessage ( ) , ex );
		}
	}
	
}
